<template>
  <div>
    <p class="title">直播列表</p>
    <div class="main">
      <div class="he">
        <div class="box1">
          <span>直播类型：</span>
          <el-select v-model="value1" placeholder="全部" size="small">
            <el-option
              v-for="item in options"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>

          <span>状态：</span>
          <el-select v-model="value2" placeholder="全部" size="small">
            <el-option
              v-for="item in options2"
              :key="item.value"
              :label="item.label"
              :value="item.value"
            >
            </el-option>
          </el-select>
        </div>
         <div >
        <div  class="search">
          <div class="el-icon-search"></div>
          <el-input
            class="seainput "
            type="text"
            placeholder="搜索用户/动态标题"
            v-model="input"
          @keyup.enter.native="search" @blur="search"
          />
        </div>
      </div>
      </div>
      <el-button type="primary" @click="broadcast">发起直播</el-button>
    </div>
    <!-- 表格 -->
    <el-table
      ref="multipleTable"
      :data="tableData"
      tooltip-effect="dark"
      style="width: 100%"
      border
    >
      <el-table-column label="序号" width="120" type="index" align="center">
        <!-- <template slot-scope="scope">{{ scope.row.date }}</template> -->
      </el-table-column>
      <el-table-column
        prop="liveTitle"
        label="直播标题"
        width="120"
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="atyName"
        label="关联活动"
        show-overflow-tooltip
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="nickname"
        label="直播人"
        show-overflow-tooltip
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="watchs"
        label="观看人数"
        show-overflow-tooltip
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="views"
        label="浏览量"
        show-overflow-tooltip
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="liveState"
        label="直播类型"
        show-overflow-tooltip
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="rec"
        label="是否推荐"
        show-overflow-tooltip
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop="state"
        label="状态"
        show-overflow-tooltip
        align="center"
      >
      </el-table-column>
      <el-table-column
        prop=""
        label="操作"
        show-overflow-tooltip
        width="120"
        align="center"
      >
        <template slot-scope="scope">
          <el-link type="primary" @click="tongguo(scope.row)">通过</el-link>
          <el-link type="primary">不通过</el-link> </template
        >>
      </el-table-column>
    </el-table>
    <!-- 分页 -->
    <Page
      :total="total"
      :pageNumber.sync="pageNumber"
      :pageSize.sync="pageSize"
      @current-change="changeCurrentPage"
      @size-change="handleSizeChange"
    >
    </Page>
  </div>
</template>

<script>
import Page from "../../components/page.vue";
import apis from "../../apis/modules/liveBroadcast";
export default {
  components: {
    Page,
  },
  data() {
    return {
      // 分页默认值

      content: "",
      pageNumber: "1",
      pageSize: "10",
      total: null,
      currentPage: 1,
      options2: [
        {
          value: "all",
          label: "全部",
        },
        {
          value: "1",
          label: "上架",
        },
        {
          value: "2",
          label: "下架",
        },
      ],

      value1: "all",
      options: [
        {
          value: "all",
          label: "全部",
        },
        {
          value: "1",
          label: "未直播",
        },
        {
          value: "2",
          label: "直播中",
        },
        {
          value: "3",
          label: "直播回放",
        },
      ],

      value2: "all",
      input: "",
      tableData: [],
    };
  },
  mounted() {
    this.getLiveBroadcast({
      liveState: this.value1,
      state: this.value2,
      pageNumber: this.pageNumber,
      pageSize: this.pageSize,
    });
  },
  watch: {
    value1() {
      console.log(this.value1);
      this.getLiveBroadcast({
        liveState: this.value1,
        state: this.value2,
        pageNumber: this.pageNumber,
        pageSize: this.pageSize,
      });
    },
    value2() {
      console.log(this.value2);
      this.getLiveBroadcast({
        liveState: this.value1,
        state: this.value2,
        pageNumber: this.pageNumber,
        pageSize: this.pageSize,
      });
    },
  },
  methods: {
    //搜索
    search(){
        this.getLiveBroadcast({
          liveState: this.value1,
        state: this.value2,
        pageNumber: this.pageNumber,
        pageSize: this.pageSize,
        content:this.input
        })
      
    },
    // 获取直播列表
    async getLiveBroadcast(data) {
      await apis.getLiveBroadcast(data).then((res) => {
        if (res.code == 200) {
          this.total = res.data.count;
          this.tableData = res.data.list;
          const list = this.tableData;
          list.map((res) => {
            switch (res.liveState) {
              case "1":
                res.liveState = "未直播";
                break;
              case "2":
                res.liveState = "直播中";
                break;
              case "3":
                res.liveState = "直播回放";
                break;

              default:
                break;
            }
            switch (res.rec) {
              case "1":
                res.rec = "是";
                break;
              case "2":
                res.rec = "否";
                break;

              default:
                break;
            }
            switch (res.state) {
              case "1":
                res.state = "上架";
                break;
              case "2":
                res.state = "下架";
                break;

              default:
                break;
            }
            return res;
          });
        }

        console.log(res);
      });
    },

    broadcast() {
      console.log("发起直播");
    },
    //分页
    changeCurrentPage(val) {
      this.pageNumber = val;
      const list = {
         liveState: this.value1,
        state: this.value2,
        pageNumber: this.pageNumber,
        pageSize: this.pageSize,
        content:this.input
      };
      this.getLiveBroadcast(list);
      console.log(val, 333);
    },
    handleSizeChange(val) {
      this.pageSize = val;
      const list = {
        liveState: this.value1,
        state: this.value2,
        pageNumber: this.pageNumber,
        pageSize: this.pageSize,
        content:this.input
      };

      this.getLiveBroadcast(list);
      console.log(val, 222);
    },
  },
};
</script>

<style lang="scss" scoped>
.title {
  margin-top: -10px;
  font-size: 14px;
}
.main {
  padding: 20px;
}
.el-input--small .el-input__inner {
  height: 32px;
  line-height: 32px;
  width: 126px;
}
.he {
  font-size: 14px;
  display: flex;
  justify-content: space-between;
  .box1 {
    width: 700px;
  }
  .el-select {
    margin-right: 40px;
  }
}
.box2 {
  width: 240px;
  height: 32px;
  line-height: 32px;
  display: flex;
  input {
    width: 240px;
    height: 32px;
    border-style: none;
    outline: none;
    margin-left: 10px;
  }
}
.el-button--primary {
  margin-top: 24px;
  width: 88px;
  height: 30px;
  line-height: 5px;
  float: right;
  margin-bottom: 20px;
}
.search {
 /deep/.el-input__inner {
    -webkit-appearance: none;
    background-color: #DCDFE6;
    background-image: none;
    border-radius: 8px;
    border: 1px solid #DCDFE6;
    box-sizing: border-box;
    color: #606266;
    display: inline-block;
    font-size: inherit;
    height: 40px;
    line-height: 40px;
    outline: 0;
    padding: 0 15px;
    transition: border-color .2s cubic-bezier(.645,.045,.355,1);
    width: 100%;
}
  height: 40px;
  background: #DCDFE6;
  // margin-top: 30px;
  display: flex;
      border-radius: 8px;
  .el-icon-search{
    line-height: 40px;
    height: 40px;
  }
 
}
</style>